import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.Arrays;

import org.kohsuke.asm5.ClassReader;
import org.kohsuke.asm5.ClassVisitor;
import org.kohsuke.asm5.MethodVisitor;
import org.kohsuke.asm5.Opcodes;
import org.kohsuke.asm5.Type;

public class Main {
	public static void main(String[] args) {
		InputStream is = null;
		try {
			String basePath = new File(Main.class.getResource("/").toURI()
					.getPath()).getParent();
			ClassReader rd = new ClassReader(is = new FileInputStream(basePath
					+ "/clazz/ITestCSV.class"));
			rd.accept(new ClassVisitor(Opcodes.ASM5) {
				@Override
				public void visit(int version, int access, String name,
						String signature, String superName, String[] interfaces) {
					System.out.println("class name:" + name);
					System.out.println("class superName:" + superName);
					System.out.println("class interfaces:"
							+ Arrays.toString(interfaces));
					super.visit(version, access, name, signature, superName,
							interfaces);
				}

				@Override
				public MethodVisitor visitMethod(int access, String name,
						String desc, String signature, String[] exceptions) {
					System.out.println("method name:" + name);
					Type[] argTypes = Type.getArgumentTypes(desc);
					String[] argTypeNames = new String[argTypes.length];
					for (int i = 0; i < argTypes.length; i++)
						argTypeNames[i] = argTypes[i].getClassName();
					System.out.println("method parameter type:"
							+ Arrays.toString(argTypeNames));
					System.out.println("method return type:"
							+ Type.getReturnType(desc).getClassName());
					System.out.println("method exceptions:"
							+ Arrays.toString(exceptions));
					return new MethodVisitor(Opcodes.ASM5) {
						@Override
						public void visitParameter(String name, int access) {
							System.out.println("method parameter:" + name);
							super.visitParameter(name, access);
						}
					};
				}
			}, 0);

		} catch (IOException e) {
			e.printStackTrace();
		} catch (URISyntaxException e) {
			e.printStackTrace();
		} finally {
			if (is != null)
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		}
	}
}
